package logic

import (
	"backend/apps/book/models"
	"context"
	"time"

	"backend/apps/book/proto"
	"backend/apps/book/rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateCategoryLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateCategoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateCategoryLogic {
	return &CreateCategoryLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// CreateCategory 分类相关操作
func (l *CreateCategoryLogic) CreateCategory(in *proto.Category) (*proto.CommonResponse, error) {
	now := time.Now().Unix()
	_, err := l.svcCtx.CategoryModel.Insert(l.ctx, &models.Category{
		Name:       in.Name,
		CreateTime: now,
		UpdateTime: now,
	})
	return &proto.CommonResponse{}, err
}
